package com.newstart.controller;

import com.newstart.bean.User;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by liushijie on 2018/5/28.
 */
@RestController
public class StartController {

    @RequestMapping(value = "user/{id}", method = RequestMethod.GET)
    public User getUser(@PathVariable Long id) {
        System.out.println("serverA");
        User u = new User();
        u.setNickname("serverA");
        return u;
    }

    @RequestMapping(value = "session", method = RequestMethod.GET)
    public String getSession(HttpServletRequest req) {
        return (String) req.getSession().getAttribute("session");
    }

    @RequestMapping(value = "session", method = RequestMethod.PUT)
    public void setSession(HttpServletRequest req) {
        req.getSession().setAttribute("session", "cloud");
    }

}
